home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Plurals / mp_object.m < prev    next >
Text File  |  1992-05-12  |  3KB  |  125 lines

  1. /*
  2.  *    MP Objects
  3.  *
  4.  *    Author:    S.C.Merrall
  5.  *
  6.  *    File:    mp_object.m
  7.  *
  8.  *    Contents:    error
  9.  *            destroy_mp_object
  10.  *
  11.  *    Description:    I am attempting to write this code is an object
  12.  *                      orientated fashion. Objects in the system are 
  13.  *                      always of the form make_OBJECT and these objects
  14.  *                      are accessed via functions from this file. They
  15.  *                      are all macros but this should give a nice 
  16.  *                      generic feel to it.
  17.  *                         The function error handles exceptions caused by 
  18.  *                      applying functions to objects of the wrong type or
  19.  *                      null objects. It is wrapped around the variable 
  20.  *                      being dereferenced within the Macro used for 
  21.  *                      accessing the appropriate slot.
  22.  *
  23.  *    Change History:
  24.  *
  25.  *    Date   Name Comment
  26.  *    -------- ---- -------
  27.  *    04:02:91 SCM  Created
  28.  *    18:02:91 SCM  Proper naming convention plus generic accessors
  29.  *    19:02:91 SCM  Added destroy_mp_object
  30.  *    28:08:91 SCM  Combined free and type into 32 bit word
  31.  *
  32.  */
  33.  
  34. #include <stdio.h>
  35.  
  36. #include "mp_object.h"
  37. #include "mp_debug_off.h"
  38.  
  39. #ifdef __STDC__
  40.  
  41. object error( object OBJECT, char *f_name, int expected_type )
  42.  
  43. #else
  44.  
  45. object error( OBJECT, f_name, expected_type )
  46.  
  47. object OBJECT;
  48. char *f_name;
  49. int expected_type;
  50.  
  51. #endif
  52.  
  53. {
  54.   if (OBJECT == NULL)
  55.     {
  56.       fprintf(stderr, "ERROR: %s applied to null object in %s\n",
  57.           f_name,dbg_g_fname);
  58.       exit(1);
  59.     }
  60.  
  61.   if (expected_type == OI_make) return OBJECT;
  62.   if (OM_freep(OBJECT))
  63.     {
  64.       fprintf(stderr, "ERROR: %s applied to freed object type %d in %s\n",
  65.           f_name, OM_type(OBJECT), dbg_g_fname);
  66.       exit(1);
  67.     }
  68.  
  69.   if ((OM_type(OBJECT) & OD_DYNAMIC) == OD_DYNAMIC) {
  70.  
  71.     if (strcmp(f_name,"OF_destroy") == 0) {
  72.       
  73.       fprintf(stderr,"ERROR: OF_destroy applied to dynamic class %x, in %s\n",
  74.           OM_type(OBJECT)-OD_DYNAMIC, dbg_g_fname);
  75.       exit(1);
  76.     }
  77.   }
  78.  
  79.  
  80.   if (expected_type == OI_Generic) return OBJECT;
  81.  
  82.  
  83.   if ((OM_type(OBJECT)  & expected_type) == 0)
  84.     {
  85.     fprintf(stderr,"ERROR: %s applied to class %x, expected class %x in %s\n",
  86.           f_name, OM_type(OBJECT), expected_type, dbg_g_fname );
  87.       exit(1);
  88.     }
  89.  
  90.   return OBJECT;
  91.  
  92. }
  93.  
  94. #ifdef __STDC__
  95.  
  96. visible int destroy_mp_object( object G_to_be_destroyed )
  97.  
  98. #else
  99.  
  100. visible int destroy_mp_object( G_to_be_destroyed )
  101.  
  102. object G_to_be_destroyed;
  103.  
  104. #endif
  105.  
  106. {
  107.   return OF_destroy(G_to_be_destroyed);
  108.  
  109.  
  110. #ifdef __STDC__
  111.  
  112. object no_constructor( void  )
  113.  
  114. #else
  115.  
  116. object no_constructor( )
  117.  
  118. #endif
  119.  
  120. {
  121.   fprintf(stderr,"ERROR: No constructor, attempted from %s\n", dbg_g_fname);
  122.   exit(1);
  123. }
  124.